import { INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

/**
 * 生成swagger
 * @param app nest应用程序
 * @param enableSwagger 是否启用swagger
 */
export const generateSwagger = (app: INestApplication) => {
  // 配置api文档信息
  const options = new DocumentBuilder()
    .setTitle('因士中台主服务API文档')
    .setDescription('因士中台主服务API文档')
    .addBearerAuth({ type: 'apiKey', in: 'header', name: 'Authorization' })
    .setVersion('0.0.1')
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('swagger', app, document, {
    explorer: true,
    swaggerOptions: {
      docExpansion: false, //该参数表示默认为折叠状态
      defaultModelsExpandDepth: 0,
      deepLinking: true
    }
  });
};
